package com.halley.serviceprovider.service;

import com.halley.servicecontract.entity.User;
import com.halley.servicecontract.service.UserContract;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
public class UserService implements UserContract {
    private static final Set<User> userSet = new HashSet<>();
    @Override
    public void add(User user) {
        userSet.add(user);
    }

    @Override
    public Optional<User> findByName(String name) {
        return userSet.stream().filter(user -> {
            return user.getName().equals(name);
        }).findFirst();
    }

    @Override
    public List<User> findAll() {
        return new ArrayList<>(userSet);
    }

    @Override
    public String findUserName(String username) {
        return "halley says hi to "+username;
    }
}
